package com.dy.course.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.dy.course.common.BaseController;
import com.dy.course.common.ResponseMessage;
import com.dy.course.entity.GroupsInfo;
import com.dy.course.model.User;
import com.dy.course.service.IGroupsService;

@Controller
public class GroupsController extends BaseController{
	
	@Autowired
	private IGroupsService groupService;
	/**
	 * 群组创建接口
	 * 
	 * @param mc
	 * @return
	 */
	@RequestMapping(value = "/group/create", method = RequestMethod.POST)
	@ResponseBody
	public ResponseMessage<?> crateGroup(@RequestBody GroupsInfo gb) {
		logger.info("【创建群组接口】,参数:gb=" + JSON.toJSONString(gb));
		groupService.insertGroup(gb);
		return constructNullResponse();
	}
	
	/**
	 * 群组查询接口
	 * 
	 * @param mc
	 * @return
	 */
	@RequestMapping(value = "/group/select")
	@ResponseBody
	public ResponseMessage<List<GroupsInfo>> selectGroup(GroupsInfo gb) {
		logger.info("【查询群组接口】,参数:gb=" + JSON.toJSONString(gb));
		return constructResponse(groupService.selectGroup(gb));
	}
	
	
	/**
	 * 群组用户信息查询接口
	 * 
	 * @param mc
	 * @return
	 */
	@RequestMapping(value = "/group/member")
	@ResponseBody
	public ResponseMessage<List<User>> selectGroupUser(GroupsInfo gb) {
		logger.info("【群组用户信息接口】,参数:gb=" + JSON.toJSONString(gb));
		return constructResponse(groupService.selectGroupUser(gb));
	}
	
	
	/**
	 * 群组删除
	 * 
	 * @param mc
	 * @return
	 */
	@RequestMapping(value = "/group/delete", method = RequestMethod.POST)
	@ResponseBody
	public ResponseMessage<?> deleteGroup(@RequestBody GroupsInfo gb) {
		logger.info("【群组信息删除接口】,参数:gb=" + JSON.toJSONString(gb.getGroupId()));
		groupService.deleteGroup(gb);
		return constructNullResponse();
	}
	
	
	/**
	 * 群组删除
	 * 
	 * @param mc
	 * @return
	 */
	@RequestMapping(value = "/group/update", method = RequestMethod.POST)
	@ResponseBody
	public ResponseMessage<?> updateGroup(@RequestBody GroupsInfo gb) {
		logger.info("【群组信息修改接口】,参数:gb=" + JSON.toJSONString(gb.getGroupId()));
		groupService.updateGroup(gb);
		return constructNullResponse();
	}
	
	
	/**
	 * 群组删除
	 * 
	 * @param mc
	 * @return
	 */
	@RequestMapping(value = "/group/create/user", method = RequestMethod.POST)
	@ResponseBody
	public ResponseMessage<?> createUserGroup(@RequestBody GroupsInfo gb) {
		logger.info("【群组信息添加用户接口】,参数:gb=" + JSON.toJSONString(gb.getGroupId()));
		groupService.insertGroupUser(gb);
		return constructNullResponse();
	}
}
